package com.zt.ztzx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zt.ztzx.model.dto.system.SysRoleDto;
import com.zt.ztzx.model.entity.system.SysRole;
import com.zt.ztzx.model.vo.common.Result;
import com.zt.ztzx.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: SysRoleController
 * @Desrciption: Mr.chengfenzhan
 * @Author: 知安_程烽展
 * @Date: 2024/8/20 14:23
 */
@RestController
@RequestMapping("/sysrole")
@Tag(name = "角色管理",description = "角色管理")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    @GetMapping("/list/{pageNum}/{pageSize}")
    @Operation(summary = "角色列表", description = "角色列表",method = "list方法")
    @Parameters({
        @Parameter(name = "sysRoleDto",description = "角色查询条件",required = true),
        @Parameter(name = "pageNum",description = "当前页码",required = true),
        @Parameter(name = "pageSize",description = "每页显示条数",required = true)
    })
    public Result<Page<SysRole>> list(SysRoleDto sysRoleDto, @PathVariable("pageNum")Integer pageNum, @PathVariable("pageSize")Integer pageSize){
        return sysRoleService.getPageData(sysRoleDto,pageNum,pageSize);
    }
    @PostMapping("/add")
    @Operation(summary = "添加角色", description = "添加角色",method = "add方法")
    @Parameters({
        @Parameter(name = "sysRole",description = "角色信息",required = true)
    })
    public Result add(@RequestBody SysRole sysRole){
        return sysRoleService.add(sysRole);
    }
    @DeleteMapping("/remove/{id}")
    @Operation(summary = "删除角色",description = "删除角色",method = "remove方法")
    @Parameters({
        @Parameter(name = "id",description = "角色id",required = true)
    })
    public Result remove(@PathVariable("id")Long id){
        return sysRoleService.removeData(id);
    }
    @PutMapping("/update")
    @Operation(summary = "更新角色",description = "更新角色",method = "update方法")
    @Parameters({
        @Parameter(name = "sysRole",description = "角色信息",required = true)
    })
    public Result update(@RequestBody SysRole sysRole){
        return sysRoleService.updateData(sysRole);
    }

    /**
     * 查询所有角色
     */
    @GetMapping("/findAll")
    @Operation(summary = "查询所有角色",description = "查询所有角色",method = "list方法")
    public Result<List<SysRole>> list(){
        return sysRoleService.findAll();
    }
}
